package com.im.grpc;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;
@Service
public class GrpcClientService {

    // 使用 @GrpcClient 注解，引入上面 application.yml 中配置的 client
    @GrpcClient("messageClient")
    private MessageServiceGrpc.MessageServiceBlockingStub blockingStub;
    /**
     * 发送消息示例方法
     * @param chatMessage ChatMessage 对象
     * @return SendMessageResponse
     */
    public ChatMessageProto.SendMessageResponse sendMessage(ChatMessageProto.ChatMessage chatMessage) {
        // 构造请求
        ChatMessageProto.SendMessageRequest request = ChatMessageProto.SendMessageRequest.newBuilder()
                .setMessage(chatMessage)
                .build();
        return blockingStub.sendMessage(request);// 通过阻塞式存根（blockingStub）调用服务端的 sendMessage 方法
    }
}